package com.rookieci.lib;

import android.os.SystemClock;

import java.text.SimpleDateFormat;

/**
 * Created by Administrator on 2017/3/23.
 */

public class TimeConstant {
    public static final long _1min = 60000;
    public static final long _3min = 180000;
    public static final long _5min = 300000;
    public static final long _10min = 600000;
    public static final long _20min = 1200000;
    public static final long _15min = 900000;
    public static final long _30min = 1800000;
    public static final long _1H = 3600000;
    public static final long _2H = 7200000;
    public static final long _3H = 10800000;
    public static final long _6H = 21600000;
    public static final long _12H = 43200000;
    public static final long _24H = 86400000;
    public static final long _2Day = 172800000;
    public static final long _3Day = 259200000;

    private static long serveTime;//服务器时间
    private static long openTime;//本地开机时间

    public static void setServeTime(long serveTime) {
        TimeConstant.serveTime = serveTime;
        openTime = SystemClock.elapsedRealtimeNanos() / 1000000;
    }

    public static long currentTimeMillis() {
        if (serveTime > 0) {
            long l = SystemClock.elapsedRealtimeNanos() / 1000000 - openTime;
            return l + serveTime;
        } else return System.currentTimeMillis();
    }

    /**
     * 2020/10/20 14:46:40
     */
    public static String getDataTime() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        return format.format(System.currentTimeMillis());
    }

    public static String getDataTime(long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        return format.format(time);
    }

    public static String getDataTime2(long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(time);
    }
}
